package homeworkTest;

import com.example.ssmHomework1.dao.TestDao;
import com.example.ssmHomework1.entity.ConfigA;
import com.example.ssmHomework1.entity.InstanceA;
import com.example.ssmHomework1.entity.Student;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class homeworkTest1 {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        TestDao testDao = (TestDao) appContext.getBean("testDao");
        testDao.test();
    }
/** 测试 */
/** 通过xml构造函数注入*/
@Test
    void testbyXml(){


        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        Student student1= context.getBean("Construct", Student.class);
        student1.show();
       // student1.toString();
    }
/** 通过名字自动装配*/
@Test
    void testbyXml2(){
    ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    InstanceA a = context.getBean("byName",InstanceA.class);
    a.getInstanceByA2();
}
/** 通过注解注入 */
@Test
    void testByzhujie(){
    ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    InstanceA a = context.getBean("InstanceA",InstanceA.class);
    a.getInstanceByA();
}

/** 通过Java注入 */
@Test
    void testByjava(){
    ApplicationContext context = new AnnotationConfigApplicationContext(ConfigA.class);
    Student a = context.getBean(Student.class);
    a.setName("lihua");
    a.setNumber("2023");
    a.setObj("China");
    a.show();


}
}
